Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
The url-regex npm package is a utility for matching URLs in strings using regular expressions. It can be used to find and extract URLs from text, validate URLs, and more.
Match URLs in a string
This feature allows you to find and extract all URLs present in a given string.
const urlRegex = require('url-regex');
const text = 'Check out this link: https://example.com and this one: http://example.org';
const urls = text.match(urlRegex());
console.log(urls); // ['https://example.com', 'http://example.org']
Validate a URL
This feature allows you to validate if a given string is a valid URL.
const urlRegex = require('url-regex');
const isValidUrl = urlRegex({ exact: true }).test('https://example.com');
console.log(isValidUrl); // true
Match URLs with specific protocols
This feature allows you to match URLs with specific protocols, such as 'https' or 'ftp'.
const urlRegex = require('url-regex');
const text = 'Visit our site at https://example.com or our FTP server at ftp://example.org';
const urls = text.match(urlRegex({ protocols: ['https'] }));
console.log(urls); // ['https://example.com']
linkify-it is a fast and lightweight library for finding and converting URLs in plain text into clickable links. It offers more customization options compared to url-regex, such as handling different types of links (e.g., email addresses) and providing hooks for custom link processing.
url-pattern is a utility for matching URLs against patterns. It is more focused on URL routing and matching specific URL structures, making it useful for applications like client-side routing in single-page applications. It offers more flexibility in defining and matching complex URL patterns compared to url-regex.
valid-url is a simple utility for validating URLs. It provides functions to check if a URL is valid, if it is a web URL, or if it is an HTTP/HTTPS URL. It is more focused on validation rather than extraction, making it a good choice for scenarios where URL validation is the primary requirement.
Regular expression for matching URLs
Based on this gist by Diego Perini.
$ npm install --save url-regex
var urlRegex = require('url-regex');
urlRegex().test('https://github.com');
//=> true
urlRegex().exec('This is a cool site https://github.com')[0].trim();
//=> https://github.com
'Multiple https://github.com http://google.com URLs'.match(urlRegex());
//=> ['https://github.com', 'http://google.com']
MIT © Diego Perini
FAQs
Regular expression for matching URLs
We found that url-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.